﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using HZ.Supervise.IBLL;
using HZ.Supervise.Model;
using System.Drawing;
using System.Web.UI.DataVisualization.Charting;
using HZ.Supervise.Model.Enum;
namespace HZ.Supervise.Web.Secondphase.ReportCompany
{
    public partial class ReportOfCompanyFirstLevel : BasePage
    {
        System.Data.DataTable dt;
        string AreaId = "";
        string strwhere = "";
        protected string HospitalTotal, DrugsTotal, FactoryTotal, DistributionTotal, OrderAmountTotal;
        protected string HospitalTotal_PS, DrugsTotal_PS, FactoryTotal_PS, DistributionTotal_PS, DistributionAmountTotal, StorageAmountTotal;
        public string sessionId = "";

        public ReportOfCompanyFirstLevel()
        {
            this.ModuleNo = Module.企业统计.ToString();
            this.PageOperateType = OperateType.企业统计查看.ToString();
        }

        protected void Page_Load(object sender, EventArgs e)
        {

            if (!Page.IsPostBack)
            {
                this.AreaControl1.InitAreaID = CurrentAccount.GetUser().Org.Area.AreaID;

                ViewState["query"] = URLUtil.GetSuperviseQueryFromURL(Request);
                //this.DataBindToTable();
                Databind();
                BindMSChart();
                GetStatistics();


            }
        }

        void GetStatistics()
        {
            double purchaseAmountTotal = 0;//采购总金额
            double PurchaseCountTotal = 0;
            double DistributeAmountTotal = 0;//配送总金额
            double DistributeCountTotal = 0;
            double WareHouseAmountTotal = 0;//入库金额
            double WareHouseCountTotal = 0;
            double SellAmountTotal = 0;//销售总金额
            double ReturnAmountTotal = 0;//退货总金额

            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (dt.Rows[i]["PurchaseAmountTotal"] != DBNull.Value) { purchaseAmountTotal += double.Parse(dt.Rows[i]["PurchaseAmountTotal"].ToString()); }
                
                    if (dt.Rows[i]["DistributeAmountTotal"] != DBNull.Value) { DistributeAmountTotal += double.Parse(dt.Rows[i]["DistributeAmountTotal"].ToString()); }
                 
                    if (dt.Rows[i]["WareHouseAmountTotal"] != DBNull.Value) { WareHouseAmountTotal += double.Parse(dt.Rows[i]["WareHouseAmountTotal"].ToString()); }
                 
                    if (dt.Rows[i]["SellAmountTotal"] != DBNull.Value) { SellAmountTotal += double.Parse(dt.Rows[i]["SellAmountTotal"].ToString()); }
                    if (dt.Rows[i]["ReturnAmountTotal"] != DBNull.Value) { ReturnAmountTotal += double.Parse(dt.Rows[i]["ReturnAmountTotal"].ToString()); }
                }
                this.lblCount.Text = "采购总金额为:" + purchaseAmountTotal.ToString() + ";配送总金额为:" + DistributeAmountTotal.ToString() + ";入库总金额为:" + WareHouseAmountTotal.ToString() + ";销售总金额为:" + SellAmountTotal.ToString() + ";退货总金额为:" + ReturnAmountTotal.ToString();

                //this.lblDistributionAmountTotal.Text = DistributeAmountTotal.ToString();
                //this.lblDistributionCountTotal.Text = DistributeCountTotal.ToString();
                //this.lblOrderAmountTotal.Text = purchaseAmountTotal.ToString();
                //this.lblOrderCountTotal.Text = PurchaseCountTotal.ToString();
                //this.lblWareHouseAmountTotal.Text = WareHouseAmountTotal.ToString();
                //this.lblWareHouseCountTotal.Text = WareHouseCountTotal.ToString();
            }


        }

        /// <summary>
        /// 图标曲线绑定
        /// 2011.4.6 by 张雄 modify
        /// </summary>
        private void BindMSChart()
        {
            //空为初始页
            if (dt.Rows.Count > 0)
            {
                string monch = "";//月份     

                #region 左图

                //***************** 日常采购 *****************/
                Series series1 = new Series("采购金额");
                series1.ChartType = (SeriesChartType)Enum.Parse(typeof(SeriesChartType), "Column", true);
                series1.IsValueShownAsLabel = true;
                series1.MarkerStyle = MarkerStyle.Diamond;
                series1.BorderWidth = 1;
                series1.ShadowOffset = 1;
                series1.ToolTip = "采购金额: #VAL{c} 万元";


                series1.Label = "#VAL{F}";
                series1.Color = Color.FromArgb(243, 84, 37);


                //***************** 临时采购 *****************/
                Series series2 = new Series("配送金额");
                series2.ChartType = (SeriesChartType)Enum.Parse(typeof(SeriesChartType), "Column", true);
                series2.IsValueShownAsLabel = true;
                series2.MarkerStyle = MarkerStyle.Diamond;
                series2.BorderWidth = 1;

                series2.ShadowOffset = 1;
                series2.ToolTip = "配送金额: #VAL{c}  万元";

                series2.Label = "#VAL{F}";
                series2.Color = Color.FromArgb(243, 152, 0);


                //***************** 应急采购 *****************/
                Series series3 = new Series("入库金额");
                series3.ChartType = (SeriesChartType)Enum.Parse(typeof(SeriesChartType), "Column", true);
                series3.IsValueShownAsLabel = true;
                series3.MarkerStyle = MarkerStyle.Diamond;
                series3.BorderWidth = 1;
                series3.ShadowOffset = 1;
                series3.ToolTip = "入库金额: #VAL{c} 万元";

                series3.Label = "#VAL{F}";
                series3.Color = Color.FromArgb(143, 195, 31);

                Series series4 = new Series("销售金额");
                series4.ChartType = (SeriesChartType)Enum.Parse(typeof(SeriesChartType), "Column", true);
                series4.IsValueShownAsLabel = true;
                series4.MarkerStyle = MarkerStyle.Diamond;
                series4.BorderWidth = 1;
                series4.ShadowOffset = 1;
                series4.ToolTip = "销售金额: #VAL{c} 万元";

                series4.Label = "#VAL{F}";
                series4.Color = Color.FromArgb(137, 201, 151);

                Series series5 = new Series("退货金额");
                series5.ChartType = (SeriesChartType)Enum.Parse(typeof(SeriesChartType), "Column", true);
                series5.IsValueShownAsLabel = true;
                series5.MarkerStyle = MarkerStyle.Diamond;
                series5.BorderWidth = 1;
                series5.ShadowOffset = 1;
                series5.ToolTip = "退货金额: #VAL{c} 万元";

                series5.Label = "#VAL{F}";
                series5.Color = Color.FromArgb(88, 219, 213);


                #endregion

                #region 右图

                //***************** 日常采购  ****************/
                //Series series5 = new Series("日常采购");
                //series5.ChartType = (SeriesChartType)Enum.Parse(typeof(SeriesChartType), drpmode.SelectedValue, true);
                //series5.MarkerStyle = MarkerStyle.Diamond;
                //series5.BorderWidth = 1;
                //series5.ShadowOffset = 1;
                //series5.MarkerStyle = MarkerStyle.Diamond;


                //series5.Label = "#VAL{F}";
                //series5.Color = Color.FromArgb(74, 172, 197);

                ////***************** 临时采购  ****************/
                //Series series6 = new Series("临时采购");
                //series6.ChartType = (SeriesChartType)Enum.Parse(typeof(SeriesChartType), drpmode.SelectedValue, true);
                //series6.MarkerStyle = MarkerStyle.Diamond;
                //series6.BorderWidth = 1;
                //series6.ShadowOffset = 1;
                //series6.MarkerStyle = MarkerStyle.Diamond;


                //series6.Label = "#VAL{F}";
                //series6.Color = Color.FromArgb(129, 101, 162);

                ////***************** 应急采购  ****************/
                //Series series7 = new Series("应急采购");
                //series7.ChartType = (SeriesChartType)Enum.Parse(typeof(SeriesChartType), drpmode.SelectedValue, true);
                //series7.MarkerStyle = MarkerStyle.Diamond;
                //series7.BorderWidth = 1;
                //series7.ShadowOffset = 1;
                //series7.MarkerStyle = MarkerStyle.Diamond;


                //series7.Label = "#VAL{F}";
                //series7.Color = Color.FromArgb(192, 80, 78);
                #endregion

                #region 绑定值，分3块日常采购，临时采购，应急采购（数量，采购金额）
                //int s0 = 0, s1 = 0, s2 = 0;//3种类型 0.1.2 日常采购，临时采购，应急采购
                //for (int i = 0; i < dt.Rows.Count; i++) //添加数据
                //{

                //    // serise1，series5 日常采购
                //    if (i == 0)//初始化横轴
                //    {
                //        // serise1，series5 日常采购
                //        monch = dt.Rows[0]["DayTime"].ToString();

                //        if (dt.Rows[i]["SortSorce"].ToString().Equals("0"))//基本药物
                //        {
                //            //金额
                //            series1.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), (double.Parse(dt.Rows[i]["PurchaseAmountTotal"].ToString()) / 10000).ToString());


                //            //数量
                //            series5.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), (double.Parse(dt.Rows[i]["DistributeRate"].ToString())).ToString());


                //            monch = dt.Rows[i]["DayTime"].ToString();

                //            series2.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), 0);

                //            series6.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), 0);

                //            series3.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), 0);

                //            series7.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), 0);
                //        }

                //        // serise2，series6 临时采购
                //        if (dt.Rows[i]["SortSorce"].ToString().Equals("1"))//基本药物
                //        {
                //            //金额
                //            series2.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), (double.Parse(dt.Rows[i]["PurchaseAmountTotal"].ToString()) / 10000).ToString());


                //            //数量
                //            series6.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), (double.Parse(dt.Rows[i]["DistributeRate"].ToString())).ToString());


                //            monch = dt.Rows[i]["DayTime"].ToString();

                //            series1.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), 0);

                //            series5.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), 0);

                //            series3.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), 0);

                //            series7.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), 0);
                //        }

                //        // serise3，series7 应急采购
                //        if (dt.Rows[i]["SortSorce"].ToString().Equals("2"))//基本药物
                //        {
                //            //金额
                //            series3.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), (double.Parse(dt.Rows[i]["PurchaseAmountTotal"].ToString()) / 10000).ToString());


                //            //数量
                //            series7.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), (double.Parse(dt.Rows[i]["DistributeRate"].ToString())).ToString());


                //            monch = dt.Rows[i]["DayTime"].ToString();

                //            series1.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), 0);

                //            series5.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), 0);

                //            series2.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), 0);

                //            series6.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), 0);
                //        }
                //        s0++;
                //        s1++;
                //        s2++;

                //    }
                //    else
                //    {
                //        if (dt.Rows[i]["DayTime"].ToString().Equals(monch))//第一行和第2行是同一个月份
                //        {
                //            //日常采购
                //            if (dt.Rows[i]["SortSorce"].ToString().Equals("0"))//判断是哪种采购类型
                //            {
                //                series1.Points.RemoveAt(s0 - 1);
                //                series1.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), (double.Parse(dt.Rows[i]["PurchaseAmountTotal"].ToString()) / 10000).ToString());

                //                series5.Points.RemoveAt(s0 - 1);
                //                series5.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), (double.Parse(dt.Rows[i]["DistributeRate"].ToString())).ToString());

                //                monch = dt.Rows[i]["DayTime"].ToString();

                //            }
                //            //临时采购
                //            if (dt.Rows[i]["SortSorce"].ToString().Equals("1"))//判断是哪种采购类型
                //            {
                //                series2.Points.RemoveAt(s0 - 1);
                //                series2.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), (double.Parse(dt.Rows[i]["PurchaseAmountTotal"].ToString()) / 10000).ToString());

                //                series6.Points.RemoveAt(s0 - 1);
                //                series6.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), (double.Parse(dt.Rows[i]["DistributeRate"].ToString())).ToString());

                //                monch = dt.Rows[i]["DayTime"].ToString();

                //            }
                //            //应急采购
                //            if (dt.Rows[i]["SortSorce"].ToString().Equals("2"))//判断是哪种采购类型
                //            {
                //                series3.Points.RemoveAt(s0 - 1);
                //                series3.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), (double.Parse(dt.Rows[i]["PurchaseAmountTotal"].ToString()) / 10000).ToString());

                //                series7.Points.RemoveAt(s0 - 1);
                //                series7.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), (double.Parse(dt.Rows[i]["DistributeRate"].ToString())).ToString());

                //                monch = dt.Rows[i]["DayTime"].ToString();

                //            }
                //        }
                //        else
                //        {
                //            //日常采购
                //            if (dt.Rows[i]["SortSorce"].ToString().Equals("0"))//判断是哪种采购类型
                //            {
                //                series1.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), (double.Parse(dt.Rows[i]["PurchaseAmountTotal"].ToString()) / 10000).ToString());

                //                series5.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), (double.Parse(dt.Rows[i]["DistributeRate"].ToString())).ToString());

                //                monch = dt.Rows[i]["DayTime"].ToString();

                //                series2.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), 0);
                //                series6.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), 0);
                //                series3.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), 0);
                //                series7.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), 0);
                //            }
                //            //临时采购
                //            if (dt.Rows[i]["SortSorce"].ToString().Equals("1"))//判断是哪种采购类型
                //            {
                //                series2.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), (double.Parse(dt.Rows[i]["PurchaseAmountTotal"].ToString()) / 10000).ToString());

                //                series6.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), (double.Parse(dt.Rows[i]["DistributeRate"].ToString())).ToString());

                //                monch = dt.Rows[i]["DayTime"].ToString();

                //                series1.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), 0);
                //                series5.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), 0);
                //                series3.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), 0);
                //                series7.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), 0);
                //            }
                //            //应急采购
                //            if (dt.Rows[i]["SortSorce"].ToString().Equals("2"))//判断是哪种采购类型
                //            {
                //                series3.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), (double.Parse(dt.Rows[i]["PurchaseAmountTotal"].ToString()) / 10000).ToString());

                //                series7.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), (double.Parse(dt.Rows[i]["DistributeRate"].ToString())).ToString());

                //                monch = dt.Rows[i]["DayTime"].ToString();

                //                series1.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), 0);
                //                series5.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), 0);
                //                series2.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), 0);
                //                series6.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), 0);
                //            }

                //            monch = dt.Rows[i]["DayTime"].ToString();
                //            s0++;
                //            s1++;
                //            s2++;

                //        }

                //    }

                //}
                #endregion

                #region 数据绑定到图

                //ChartPurchasing.Series.Clear();
                //ChartInStorage.Series.Clear();

                //series1.IsValueShownAsLabel = true;
                //ChartPurchasing.Series.Add(series1);

                //ChartPurchasing.Series["日常采购"].ChartArea = "ChartComPurchasing";

                //series5.IsValueShownAsLabel = true;
                //ChartInStorage.Series.Add(series5);
                //ChartInStorage.Series["日常采购"].ChartArea = "ChartComStorage";

                //series2.IsValueShownAsLabel = true;
                //ChartPurchasing.Series.Add(series2);
                //ChartPurchasing.Series["临时采购"].ChartArea = "ChartComPurchasing";

                //series6.IsValueShownAsLabel = true;
                //ChartInStorage.Series.Add(series6);
                //ChartInStorage.Series["临时采购"].ChartArea = "ChartComStorage";

                //series3.IsValueShownAsLabel = true;
                //ChartPurchasing.Series.Add(series3);
                //ChartPurchasing.Series["应急采购"].ChartArea = "ChartComPurchasing";


                //series7.IsValueShownAsLabel = true;
                //ChartInStorage.Series.Add(series7);
                //ChartInStorage.Series["应急采购"].ChartArea = "ChartComStorage";


                #endregion

                #region 两张图片属性

                //ChartPurchasing.ChartAreas["ChartComPurchasing"].AxisX.IsMarginVisible = true;
                //ChartPurchasing.ChartAreas["ChartComPurchasing"].Area3DStyle.Enable3D = false;

                //ChartInStorage.ChartAreas["ChartComStorage"].AxisX.IsMarginVisible = true;
                //ChartInStorage.ChartAreas["ChartComStorage"].Area3DStyle.Enable3D = false;


                //ChartPurchasing.ChartAreas["ChartComPurchasing"].AxisX.MajorGrid.Interval = 1;
                //ChartPurchasing.ChartAreas["ChartComPurchasing"].AxisX.LineWidth = 1;
                //ChartPurchasing.ChartAreas["ChartComPurchasing"].AxisY.LineWidth = 1;

                //ChartInStorage.ChartAreas["ChartComStorage"].AxisX.MajorGrid.Interval = 1;
                //ChartInStorage.ChartAreas["ChartComStorage"].AxisX.LineWidth = 1;
                //ChartInStorage.ChartAreas["ChartComStorage"].AxisY.LineWidth = 1;

                //ChartPurchasing.ChartAreas["ChartComPurchasing"].AxisY.Title = "金额（万元）";
                //ChartPurchasing.ChartAreas["ChartComPurchasing"].AxisX.Title = "日期";

                //ChartInStorage.ChartAreas["ChartComStorage"].AxisY.Title = "配送率";
                //ChartInStorage.ChartAreas["ChartComStorage"].AxisX.Title = "日期";
                #endregion

                #region 分组
                //ChartPurchasing.Series["日常采购"]["StackedGroupName"] = "Group1";
                //ChartPurchasing.Series["临时采购"]["StackedGroupName"] = "Group1";
                //ChartPurchasing.Series["应急采购"]["StackedGroupName"] = "Group1";

                //ChartInStorage.Series["日常采购"]["StackedGroupName"] = "Group2";
                //ChartInStorage.Series["临时采购"]["StackedGroupName"] = "Group2";
                //ChartInStorage.Series["应急采购"]["StackedGroupName"] = "Group2";

                //ChartInStorage.ResetAutoValues();
                //ChartPurchasing.ResetAutoValues();
                #endregion

                # region  1218

                #region 绑定值，分3块日常采购，临时采购，应急采购（数量，采购金额）


                for (int i = 0; i < dt.Rows.Count; i++) //添加数据
                {

                    // serise1，series5 日常采购

                    // serise1，series5 日常采购


                    //金额
                    series1.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), (double.Parse(dt.Rows[i]["PurchaseAmountTotal"].ToString()) / 10000).ToString());

                    series2.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), (double.Parse(dt.Rows[i]["DistributeAmountTotal"].ToString()) / 10000).ToString());

                    series3.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), (double.Parse(dt.Rows[i]["WareHouseAmountTotal"].ToString()) / 10000).ToString());

                    series4.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), (double.Parse(dt.Rows[i]["sellAmountTotal"].ToString()) / 10000).ToString());

                    series5.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), (double.Parse(dt.Rows[i]["ReturnAmountTotal"].ToString()) / 10000).ToString());

                    ////配送率
                    //series5.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), (double.Parse(dt.Rows[i]["DistributeRate"].ToString())).ToString());

                    monch = dt.Rows[i]["DayTime"].ToString();

                    //series2.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), 0);
                    //series2.Points[s1].ToolTip = "0";

                    //series6.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), 0);
                    //series6.Points[s1].ToolTip = "0";

                    //series3.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), 0);
                    //series3.Points[s2].ToolTip = "0";

                    //series7.Points.AddXY(HZ.Supervise.Web.Function.FormartDate(dt.Rows[i]["DayTime"].ToString()), 0);
                    //series7.Points[s2].ToolTip = "0";

                    // serise2，series6 临时采购


                    //s0++;
                    //s1++;
                    //s2++;



                }




                #endregion

                #region 数据绑定到图
                //清空Serise 避免确定按钮和下拉框同时绑定图表
                ChartPurchasing.Series.Clear();

                ChartInStorage.Series.Clear();


                ChartPurchasing.Series.Add(series1);

                //ChartInStorage.Series.Add(series5);

                ChartPurchasing.Series.Add(series2);

                //ChartInStorage.Series.Add(series6);

                ChartPurchasing.Series.Add(series3);
                ChartPurchasing.Series.Add(series4);
                ChartPurchasing.Series.Add(series5);
                //ChartInStorage.Series.Add(series7);
                #endregion

                #region 两张图片属性

                //ChartPurchasing.ChartAreas["ChartComPurchasing"].AxisX.IsMarginVisible = true;
                ChartPurchasing.ChartAreas["ChartComPurchasing"].Area3DStyle.Enable3D = true;

                //ChartInStorage.ChartAreas["ChartHosStorage"].AxisX.IsMarginVisible = true;
                //ChartInStorage.ChartAreas["ChartHosStorage"].Area3DStyle.Enable3D = false;


                //ChartPurchasing.ChartAreas["ChartComPurchasing"].AxisX.MajorGrid.Interval = 1;
                //ChartPurchasing.ChartAreas["ChartComPurchasing"].AxisX.LineWidth = 1;
                //ChartPurchasing.ChartAreas["ChartComPurchasing"].AxisY.LineWidth = 1;

                //ChartInStorage.ChartAreas["ChartHosStorage"].AxisX.MajorGrid.Interval = 1;
                //ChartInStorage.ChartAreas["ChartHosStorage"].AxisX.LineWidth = 1;
                //ChartInStorage.ChartAreas["ChartHosStorage"].AxisY.LineWidth = 1;

                ChartPurchasing.ChartAreas["ChartComPurchasing"].AxisY.Title = "金额（万元）";
                ChartPurchasing.ChartAreas["ChartComPurchasing"].AxisX.Title = "日期";

                //ChartInStorage.ChartAreas["ChartHosStorage"].AxisY.Title = "配送率";
                //ChartInStorage.ChartAreas["ChartHosStorage"].AxisX.Title = "日期";
                #endregion

                #region 分组
                ChartPurchasing.Series["采购金额"]["StackedGroupName"] = "Group1";
                ChartPurchasing.Series["配送金额"]["StackedGroupName"] = "Group1";
                ChartPurchasing.Series["入库金额"]["StackedGroupName"] = "Group1";
                ChartPurchasing.Series["销售金额"]["StackedGroupName"] = "Group1";
                ChartPurchasing.Series["退货金额"]["StackedGroupName"] = "Group1";

                ChartPurchasing.Series["采购金额"]["DrawingStyle"] = "Cylinder";
                ChartPurchasing.Series["配送金额"]["DrawingStyle"] = "Cylinder";
                ChartPurchasing.Series["入库金额"]["DrawingStyle"] = "Cylinder";
                ChartPurchasing.Series["销售金额"]["DrawingStyle"] = "Cylinder";
                ChartPurchasing.Series["退货金额"]["DrawingStyle"] = "Cylinder";

                ChartPurchasing.Series["采购金额"]["PointWidth"] = "0.6";
                ChartPurchasing.Series["配送金额"]["PointWidth"] = "0.6";
                ChartPurchasing.Series["入库金额"]["PointWidth"] = "0.6";
                ChartPurchasing.Series["销售金额"]["PointWidth"] = "0.6";
                ChartPurchasing.Series["退货金额"]["PointWidth"] = "0.6";


                //ChartInStorage.Series["日常采购"]["StackedGroupName"] = "Group2";
                //ChartInStorage.Series["临时采购"]["StackedGroupName"] = "Group2";
                //ChartInStorage.Series["应急采购"]["StackedGroupName"] = "Group2";

                //ChartInStorage.ResetAutoValues();
                ChartPurchasing.ResetAutoValues();
                #endregion
                #endregion
                //lblnull.Visible = false;
                this.divshow.Visible = true;
                this.btnExcel.Visible = true;
                //this.imgtable.Visible = true;
            }
            else//2011-0428 没数据不显示 mal
            {
                this.btnExcel.Visible = false;
                this.divshow.Visible = false;
                this.ChartInStorage.Visible = false;
                this.ChartPurchasing.Visible = false;
               // this.imgtable.Visible = false;
               // this.divjsChart.Visible = false;
               // lblnull.Visible = true;
            }
        }

        /// <summary>
        /// 合并表头
        /// by张雄  2011.5.8
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">参数</param>
        protected void gvwProcureCatalog_RowCreated(object sender, GridViewRowEventArgs e)
        {
            #region
            switch (e.Row.RowType)
            {
                case DataControlRowType.Header:
                    //第一行表头
                    TableCellCollection tcHeader = e.Row.Cells;
                    tcHeader.Clear();
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[0].Attributes.Add("colspan", "6"); //跨Column
                    SuperviseQuery sq = (SuperviseQuery)ViewState["query"];
                    tcHeader[0].Attributes.Add("bgcolor", "LightSteelBlue");

                    if ((sq.CompanyName_TB == null) && (sq.CompanyName_PS != null))
                    {
                        tcHeader[0].Text = sq.CompanyName_PS + "</th></tr><tr>";
                    }
                    else if ((sq.CompanyName_TB == null) && (sq.CompanyName_SC != null))
                    {
                        tcHeader[0].Text = sq.CompanyName_SC + "</th></tr><tr>";
                    }
                    else
                    {
                        tcHeader[0].Text = "企业汇总统计" + "</th></tr><tr>";
                    }

                    //第2行表头
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[1].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[1].Text = "日期";

                    //tcHeader.Add(new TableHeaderCell());
                    //tcHeader[2].Attributes.Add("bgcolor", "Khaki");
                    //tcHeader[2].Text = "采购类型";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[2].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[2].Text = "采购总金额";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[3].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[3].Text = "配送总金额";

                    //tcHeader.Add(new TableHeaderCell());
                    //tcHeader[5].Attributes.Add("bgcolor", "Khaki");
                    //tcHeader[5].Text = "配送率";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[4].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[4].Text = "入库总金额";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[5].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[5].Text = "销售总金额";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[6].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[6].Text = "退货总金额";

                    //tcHeader.Add(new TableHeaderCell());
                    //tcHeader[7].Attributes.Add("bgcolor", "Khaki");
                    //tcHeader[7].Text = "入库率";

                    //tcHeader.Add(new TableHeaderCell());
                    //tcHeader[8].Attributes.Add("bgcolor", "Khaki");
                    //tcHeader[8].Text = "操作";
                    break;
            }
            #endregion
        }

        /// <summary>
        /// 绑定    添加地区权限
        /// by张雄  2011.5.17
        /// </summary>
        public void Databind()
        {
            AreaId = this.AreaControl1.SelectedAreaID;      //获得当前用户控件的Id

            SuperviseQuery sq = (SuperviseQuery)ViewState["query"];
            sessionId = Guid.NewGuid().ToString();
            SuperviseQuery query = new SuperviseQuery();
            query.CompanyName_PS = sq.CompanyName_PS;
            query.CompanyType = sq.CompanyType;
            Session[sessionId] = query;
            int t = 0;

            var model = new HZ.Data.QueryModel();
            model["AreaId"] = AreaControl1.SelectedAreaID;      //获取用户控件的AreaId
            model["CompanyName"] = sq.CompanyName_PS;
            model["SortFields"] = "DayTime";
            string month = "";
            if (DateTime.Now.AddMonths(-12).Month <= 9) month = "0" + DateTime.Now.AddMonths(-12).Month.ToString();
            else month = DateTime.Now.AddMonths(-12).Month.ToString();
            string timeFrom = DateTime.Now.AddMonths(-12).Year + "" + month;
            model["append"] = "DayTime > '" + timeFrom + "'";
            //model["AreaID"] = this.AreaControl1.SelectedAreaID;

            HZ.Supervise.IBLL.IBLL_NewStat iNew = HZ.Supervise.BLLFactory.IBLL_NewStats();
            HZ.Supervise.IBLL.IExecuteContext ie = HZ.Supervise.BLLFactory.ExecuteContext();
            if (query.CompanyType == 0)
            {
                dt = iNew.DayTime_SortSorce_CompanySC_GroupBy(model, strwhere, 1, 0, out t);
            }
            else
            {
                dt = iNew.DayTime_SortSorce_Company_GroupBy(model, strwhere, 1, 0, out t);
            }
            //显示相应的字段
            DataView dv = dt.DefaultView;
            dv.Table.Locale = new System.Globalization.CultureInfo("zh-CN");
            dv.Sort = " DayTime desc ";

            DataTable NewSource = dv.ToTable();
            //HZ.Supervise.Web.Function.ChangeRate_PS(NewSource, "DistributeRate");//by张雄    2011.5.6
            //HZ.Supervise.Web.Function.AddColumn(NewSource, "SortSorce");
            //HZ.Supervise.Web.Function.ChangeRate(NewSource, "WarehouseRate");

            gvwProcureCatalog.DataSource = NewSource;

            gvwProcureCatalog.DataBind();

            //HZ.Supervise.Web.Function.Combine(gvwProcureCatalog, 0, 0);
            //HZ.Supervise.Web.Function.Combine(gvwProcureCatalog, 0, 7);

        }


    

        /// <summary>
        /// 导出数据
        /// 2011.4.7 by 张雄 create
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void btnExcel_Click(object sender, EventArgs e)
        {

            AreaId = this.AreaControl1.SelectedAreaID;      //获得当前用户控件的Id

            SuperviseQuery sq = (SuperviseQuery)ViewState["query"];
            sessionId = Guid.NewGuid().ToString();
            SuperviseQuery query = new SuperviseQuery();
            query.CompanyName_PS = sq.CompanyName_PS;
            query.CompanyType = sq.CompanyType;
            Session[sessionId] = query;
            int t = 0;

            var model = new HZ.Data.QueryModel();
            model["AreaId"] = AreaControl1.SelectedAreaID;      //获取用户控件的AreaId
            model["CompanyName"] = sq.CompanyName_PS;
            model["SortFields"] = "DayTime";
            string month = "";
            if (DateTime.Now.AddMonths(-12).Month <= 9) month = "0" + DateTime.Now.AddMonths(-12).Month.ToString();
            else month = DateTime.Now.AddMonths(-12).Month.ToString();
            string timeFrom = DateTime.Now.AddMonths(-12).Year + "" + month;
            model["append"] = "DayTime > '" + timeFrom + "'";
            model["AreaID"] = this.AreaControl1.SelectedAreaID;

            HZ.Supervise.IBLL.IBLL_NewStat iNew = HZ.Supervise.BLLFactory.IBLL_NewStats();
            HZ.Supervise.IBLL.IExecuteContext ie = HZ.Supervise.BLLFactory.ExecuteContext();
            if (query.CompanyType == 0)
            {
                dt = iNew.DayTime_SortSorce_CompanySC_GroupBy(model, strwhere, 1, 0, out t);
            }
            else
            {
                dt = iNew.DayTime_SortSorce_Company_GroupBy(model, strwhere, 1, 0, out t);
            }
            //显示相应的字段
            DataView dv = dt.DefaultView;
            dv.Table.Locale = new System.Globalization.CultureInfo("zh-CN");
            dv.Sort = " DayTime desc ";

            DataTable NewSource = dv.ToTable();
            //HZ.Supervise.Web.Function.ChangeRate_PS(NewSource, "DistributeRate");//by张雄    2011.5.6
            //HZ.Supervise.Web.Function.AddColumn(NewSource, "SortSorce");
            //HZ.Supervise.Web.Function.ChangeRate(NewSource, "WarehouseRate");

            HZ.Excel.ExcelHelper.ExportDataForWeb(NewSource, this.gvwProcureCatalog);


        }
        protected void lbtnSee_Click(object sender, EventArgs e)
        {

        }
        public override void VerifyRenderingInServerForm(Control control)
        {
            //OverRide　为了使导出成Excel可行！
            //base.VerifyRenderingInServerForm(control);

        }
        protected void gvwProcureCatalog_RowDataBound(object sender, GridViewRowEventArgs e)
        {
        }

        protected void gvwProcureCatalog_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "DirectByDetail")
            {
                string sessionid = Guid.NewGuid().ToString();
                SuperviseQuery query = URLUtil.GetSuperviseQueryFromURL(Request);
                try
                {
                    query.Mid = e.CommandArgument.ToString();
                    query.AreaID = AreaControl1.SelectedAreaID.ToString();      //把AreaId添加到Session的集合中
                }
                catch { }
                Session[sessionid] = query;
                string url = "";
                if (string.IsNullOrEmpty(query.CompanyName_PS))
                {
                    url = "CompanyOfMonth.aspx";
                }
                else   //按医院查询
                {
                    url = "CompanyCurrentGoodsList.aspx";
                }
                Response.Redirect(string.Format("{0}?sessionid={1}", url, sessionid));
            }

        }

        protected void drpmode_SelectedIndexChanged(object sender, EventArgs e)
        {
            Databind();
            BindMSChart();
            GetStatistics();
        }

        private void DataBindToTable()
        {
            HZ.Supervise.IBLL.IExecuteContext ie = HZ.Supervise.BLLFactory.ExecuteContext();

            SuperviseQuery sq = (SuperviseQuery)ViewState["query"];
            var model = new HZ.Data.QueryModel();
            if (this.AreaControl1.SelectedAreaID != "510000")
            {
                model["AreaID"] = this.AreaControl1.SelectedAreaID;
            }

            if (sq.CompanyName_PS != null)
            {
                if (sq.CompanyType == 0)
                {
                    model["CompanyName_Sc"] = sq.CompanyName_PS;

                }
                else
                {
                    model["CompanyName"] = sq.CompanyName_PS;

                }
            }


            DataTable dtChart1 = ie.GetSuperviseChart1(model);

            //if (dtChart1.Rows.Count > 0)
            //{
            //    if (dtChart1.Rows[0]["HospitalCount"] != DBNull.Value) { this.lblHospitalTotal.Text = string.Format("{0}个", dtChart1.Rows[0]["HospitalCount"].ToString()); }
            //    if (dtChart1.Rows[0]["ProcureCatalogCount"] != DBNull.Value) { this.lblDrugsTotal.Text = string.Format("{0}个", dtChart1.Rows[0]["ProcureCatalogCount"].ToString()); }
            //    if (dtChart1.Rows[0]["CompanySCCount"] != DBNull.Value) { this.lblFactoryTotal.Text = string.Format("{0}个", dtChart1.Rows[0]["CompanySCCount"].ToString()); }
            //    if (dtChart1.Rows[0]["CompanyPSCount"] != DBNull.Value) { this.lblDistributionTotal.Text = string.Format("{0}个", dtChart1.Rows[0]["CompanyPSCount"].ToString()); }

            //}

        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            Databind();
            BindMSChart();
            GetStatistics();
        }
    }
}
